package request;

import javax.servlet.ServletException;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 演示使用 requset 对象获取浏览器
 */
public class IdentifyUserAgent extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String agent = req.getHeader("User-Agent");
        PrintWriter writer = resp.getWriter();
        writer.println(agent);
        if (agent.contains("Firefox"))
            writer.println("FireFox");
        else if (agent.contains("Chrome"))
            writer.println("Chrome");
        else if (agent.contains("MSIE"))
            writer.println("IE");
        else
            writer.println("Unknow");
    }
}
